<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		手机号
		<input  value="" name="phone" placeholder="请输入手机号"/>
		
		验证码
		<input  value="" name="code" placeholder="请输入验证码 "/>
		
		<button> 获取验证码</button>
		
		
		<script>
			
			
			// 循环定时器
			
			// 点击事件
			
			var btn = document.getElementsByTagName("button")[0];
			
			var count = 10;
	
			var timer = null;
			
			btn.onclick = function(){
				
				console.log(timer)
				
				if(timer){
					
					return false;
				}
				
				timer = window.setInterval(function(){
					
					count -- ;
					btn.innerText = count+'s';  // 如果 用this,那么this指向的是window 对象，非 button
					
					if(count==0){
						btn.innerText = "获取验证码";
						count = 10;
						
						clearInterval(timer);
						
						timer = null;
					}
					
					
					
				},1000);
				
				
				
				
			}
			
			
			
		</script>
		
		
	</body>
</html>